package plp.functional2.expression;

import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

import plp.expressions1.util.Tipo;
import plp.expressions2.expression.Expressao;
import plp.expressions2.expression.Valor;
import plp.expressions2.memory.AmbienteCompilacao;
import plp.expressions2.memory.AmbienteExecucao;
import plp.expressions2.memory.VariavelJaDeclaradaException;
import plp.expressions2.memory.VariavelNaoDeclaradaException;
import plp.functional1.expression.TuplaException;

public class ExpMap implements Expressao {

	private List maps;

	public ExpMap(List maps) {
		this.maps = maps;
	}

	public Valor avaliar(AmbienteExecucao amb)
			throws VariavelNaoDeclaradaException, VariavelJaDeclaradaException,
			TuplaException, MapException {
		HashMap<Valor, Valor> auxiliar = new HashMap<Valor, Valor>();
		
		for (Iterator iterator = maps.iterator(); iterator.hasNext();) {
			ExpMapEntry expMapEntry = (ExpMapEntry) iterator.next();
			ValorMapEntry valorMapEntry = (ValorMapEntry) expMapEntry.avaliar(amb);
			auxiliar.put(valorMapEntry.getKey(), valorMapEntry.getValue());
		}
		
		
		return new ValorMap(auxiliar);
	}

	public boolean checaTipo(AmbienteCompilacao amb)
			throws VariavelNaoDeclaradaException, VariavelJaDeclaradaException {
		return true;
	}

	public Tipo getTipo(AmbienteCompilacao amb)
			throws VariavelNaoDeclaradaException, VariavelJaDeclaradaException {
		return Tipo.TIPO_MAP;
	}

}
